import strutils, sequtils, math

proc encrypt*(plain: string): string =
  var
    normal = plain.toLower.filterIt(it in (Letters + Digits)).join
    r = int(normal.len.float.sqrt + 0.5)
    c = if r ^ 2 < normal.len: r + 1 else: r
  if r < 2:
    return normal
  normal.add repeat(' ', c * r - normal.len)
  for i in 0..<c:
    if result.len > 0: result.add ' '
    for j in 0..<r:
      result.add normal[j * c + i]
    
